@extends('admin.layout.app')
@section('title', '权限管理')

@section('nav')
    @include('admin.layout.nav', ['title'=> ['系统管理','编辑权限']])
@endsection

@section('content')
    <div class="box box-primary" style="min-height: 300px;">
        <div class="box-header with-border">
            <h3 class="box-title">编辑</h3>
        </div>
        <!-- /.box-header -->
        <form action="" method="post" id="add-form" autocomplete="off">
            {{ csrf_field() }}
            <input name="id" value="{{$permission->id}}" style="display: none;"/>
            <div class="box-body">
                <div class="form-group">
                    <label for="name">权限名：</label>
                    <input type="text" class="form-control" name="name" value="{{$permission->name}}" placeholder="请输入">
                    @if($errors->has('name'))
                        <label class="control-label error" for="inputError1">{{$errors->first('name')}}</label>
                    @endif
                </div>
                <div class="form-group">
                    <label for="display_name">显示名：</label>
                    <input type="text" class="form-control" name="display_name" value="{{$permission->display_name}}"  placeholder="请输入">
                    @if($errors->has('display_name'))
                        <label class="control-label error" for="inputError1">{{$errors->first('display_name')}}</label>
                    @endif
                </div>
                <div class="form-group">
                    <label for="description">描述：</label>
                    <input type="text" class="form-control" name="description" value="{{$permission->description}}"  placeholder="请输入">
                    @if($errors->has('username'))
                        <label class="control-label error" for="inputError1">{{$errors->first('description')}}</label>
                    @endif
                </div>
            </div>
            <!-- /.box-body -->

            <div class="box-footer">
                <input type="submit" class="btn btn-primary" value="提交">
                <a class="btn btn-default" href="javascript:window.history.back();">返回</a>
            </div>
        </form>

    </div>
@endsection

@section('style')
    <link rel="stylesheet" href="/lib/jquery.validation/1.14.0/validation.css">
    <style>

    </style>
@endsection

@section('js')
    <script type="text/javascript" src="/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script >
        $(function(){
            $("#add-form").validate({
                rules: {
                    name: {
                        required: true,
                        maxlength: 30
                    },
                    display_name: {
                        required: true,
                        maxlength: 30
                    },
                    description: {
                        maxlength: 50
                    }
                },
                messages: {
                    name: {
                        required: "请输入权限名",
                        maxlength: '权限名不能超过30个字符'
                    },
                    display_name:{
                        required: "请输入显示名",
                        maxlength: '显示名不能超过30个字符'
                    },
                    description: {
                        maxlenght: "不能超过50个字符"
                    }
                },
                errorPlacement: function(error, element) {
                    error.appendTo(element.parent());
                }
            })
        })
    </script>
@endsection